package ui.action;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import lecture.Lecture;
import ui.UIMainWin;
import ui.UIRows;

@SuppressWarnings("serial")
public class ActionEditLecture extends AbstractAction{
	
	private UIMainWin win;
	
	public ActionEditLecture(String name, UIMainWin win){
		super(name);
		this.win = win;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		int selectedRow = win.getLectureTable().getSelectedRow();
		if(selectedRow != -1){
			Lecture selectedLecture = UIRows.getLectureRow().get(selectedRow);
			selectedLecture.setCode("edited");

			win.getSm().storeEditedEntity(selectedLecture);
			win.refreshLectureTable();
		}
		else{
			JOptionPane.showMessageDialog(win,
				    "No selected row",
				    "Error",
				    JOptionPane.ERROR_MESSAGE);
		}
		
		
	}

}
